from haystack import component
from haystack.components.agents import Agent
from haystack.tools.component_tool import ComponentTool

from haystack.dataclasses import Document, ChatMessage
from haystack.components.generators.chat import OpenAIChatGenerator

from typing import List
from haystack.utils.auth import Secret

# Create the web search component
 
# Create the ComponentTool with simpler parameters
 


# Create the agent with the web tool
tool_calling_agent = Agent(
    chat_generator=OpenAIChatGenerator(model="DeepSeek-R1",api_base_url='https://api.deepseek.com',api_key=Secret.from_token(  'sk-605e60a1301040759a821b6b677556fb')),
    system_prompt="""You're a helpful agent. When asked about current information like weather, news, or facts, 
                     use the web_search tool to find the information and then summarize the findings.
                     When you get web search results, extract the relevant information and present it in a clear, 
                     concise manner.""",

)

# Run the agent with the user message
user_message = ChatMessage.from_user("How is the weather in Berlin?")
result = tool_calling_agent.run(messages=[user_message])

# Print the result - using .text instead of .content
print(result["messages"][-1].text)